package ch.ethz.eai.handler;

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeader;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.handlers.AbstractHandler;

public class AuthHandler extends AbstractHandler{

	@Override
	public InvocationResponse invoke(MessageContext mc) throws AxisFault {
		SOAPEnvelope env = mc.getEnvelope();
		SOAPHeader header = env.getHeader();
		SOAPFactory factory = (SOAPFactory) env.getOMFactory();
		OMNamespace ns = factory.createOMNamespace("http://ws.apache.org/axis2", "hns");
		SOAPHeaderBlock head = header.addHeaderBlock("userToken", ns);
		OMElement el = factory.createOMElement("secretToken", ns);
		head.addChild(el);
		return InvocationResponse.CONTINUE; 
	}

}